package com.booksmanager.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.booksmanager.annotation.Log;
import com.booksmanager.pojo.Readers;
import com.booksmanager.service.ReadersService;
import com.booksmanager.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 读者表 前端控制器
 * </p>
 *
 * @author Yan
 * @since 2020-05-24
 */
@Api(value = "/readers", tags = "读者表模块")
@RestController
@RequestMapping("/readers")
public class ReadersController {

    @Autowired
    private ReadersService readersService;


    /**
     * 分页查询读者列表
     *
     * @param page
     * @param readers
     * @return
     */
    @ApiOperation(value = "分页查询读者列表")
    @GetMapping("/page")
    public R page(Page page, Readers readers) {
        return new R(readersService.page(page, Wrappers.lambdaQuery(readers)));
    }


    /**
     * 新增读者
     *
     * @param readers
     * @return
     */
    @ApiOperation(value = "新增读者")
    @Log("新增读者")
    @PostMapping("/save")
    public R save(@RequestBody Readers readers) {
        return new R(readersService.save(readers));
    }


    /**
     * 更新读者
     *
     * @param readers
     * @return
     */
    @ApiOperation(value = "更新读者")
    @Log("更新读者")
    @PutMapping("/update")
    public R update(@RequestBody Readers readers) {
        return new R(readersService.updateById(readers));
    }


    /**
     * 删除读者
     *
     * @param readers
     * @return
     */
    @ApiOperation(value = "删除读者")
    @Log("删除读者")
    @DeleteMapping("/delete")
    public R delete(@RequestBody Readers readers) {
        readers.setDelFlag("-1");
        return new R(readersService.updateById(readers));
    }
}

